package com.quick.develop.framework.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quick.develop.flowable.domain.page.PageParam;
import com.quick.develop.framework.common.page.PageResult;

public class MybatisUtils {

    private static final String MYSQL_ESCAPE_CHARACTER = "`";

    public static <T> Page<T> buildPage(PageParam pageParam) {
        // 页码 + 数量
        return new Page<>(pageParam.getPageNo(), pageParam.getPageSize());
    }

    public static <T> PageResult<T> selectPage(SelectPage selectPage, PageParam pageParam) {
        IPage<T> page = new Page<>(pageParam.getPageNo(), pageParam.getPageSize());
        IPage<T> iPage = selectPage.apply(page);
        return new PageResult<>(iPage);
    }

    @FunctionalInterface
    public interface SelectPage {
        <T> IPage<T> apply(IPage<T> page);
    }
}
